/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-03-14
 * Time: 21:11
 */
public class TestDate {
    public int year;
    public int month;
    public int day;


    public TestDate() {
        System.out.println("没有参数的构造方法");
    }
    public TestDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
        System.out.println("有参数的构造方法");
    }

    //构造方法可以重载
    public void setDay1(int y, int m, int d){
        year = y;
        month = m;
        day = d;
    }
    public void setDay2(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
//        year = year;
//        month = month;
//        day = day;
        //局部 = 全局
    }
    public void printDate1(){
        System.out.println(year + "/" + month + "/" + day);
    }
    public void printDate2(TestDate this/*一般会被隐藏*/){
        System.out.println(this.year + "/" + this.month + "/" + this.day);
    }

    public static void main(String[] args) {
        TestDate testDate1 = new TestDate();
//        testDate1.month = 5;
//        testDate1.day = 25;
        TestDate testDate2 = new TestDate();
        TestDate testDate3 = new TestDate();//调用没有参数的构造方法
        //构造方法如果一个都没写，那么编译器就会默认生成一个没有参数的构造方法
        //一旦写了任何的构造方法，那么Java就不会生成构造方法
        testDate1.setDay2(1998,12,24);
        testDate2.setDay2(2004,2,6);
        testDate3.setDay2(2005,8,19);

        testDate1.printDate2();
        testDate2.printDate2();
        testDate3.printDate2();


//        int a;
//        System.out.println(a);//局部变量需要先初始化才能使用
    }

    public static void main1(String[] args) {

    }
}
